import 'package:flutter/material.dart';
import 'dialog.dart';


TextStyle resTextStyle = TextStyle(inherit: false, fontSize: 13, height: 1.2);
TextStyle resTextStyle3 = TextStyle(
    inherit: false, color: Color(0xff333333), fontSize: 13, height: 1.2);
TextStyle resTextStyle6 = TextStyle(
    inherit: false, color: Color(0xff666666), fontSize: 13, height: 1.2);

class AffirmDialog extends StatelessWidget {
  final String? title;
  final String? message;
  final String? textLeftButton;
  final String? textRightButton;
  final VoidCallback? onLeftClick;
  final VoidCallback? onRightClick;
  final VoidCallback? onBackgroundClick;
  final List<TextSpan>? textSpan;

  AffirmDialog({this.title,
    this.message,
    this.onLeftClick,
    this.onRightClick,
    this.textSpan,
    this.onBackgroundClick,
    this.textRightButton,
    this.textLeftButton});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).pop();
        if (onBackgroundClick != null) {
          onBackgroundClick!();
        }
      }, child: Container(
      alignment: Alignment.center,
      color: Color(0x01000000),
      padding: EdgeInsets.only(left: 37, right: 37),
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(
                textLeftButton == null ? 8 : 14)),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(
              height: 16,
            ),
            Container(
              height: 21,
              child: Stack(
                children: [
                  Center(
                    child: Text(
                      title!,
                      style: resTextStyle.copyWith(
                          color: Color(0xff222222),
                          fontSize: 16,
                          fontWeight: FontWeight.w600),
                    ),
                  ),
                  if(textLeftButton == null)
                    Positioned(
                        right: 16,
                        child: GestureDetector(
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                          child: Container(
                            width: 20,
                            height: 20,
                            decoration: BoxDecoration(color: Color(0xfff3f3f3),
                              borderRadius: BorderRadius.circular(20),),
                            child: Icon(Icons.clear_rounded, size: 13,
                                color: Color(0xff666666)),
                          ),
                        ))
                ],
              ),
            ),
            SizedBox(
              height: 10,
            ),
            Padding(
              padding: EdgeInsets.only(
                  left: 25, right: textLeftButton == null ? 30 : 25),
              child: textSpan!=null?
              RichText(text: TextSpan(children:textSpan))
                  :Text(
                message!,textAlign: TextAlign.center,
                style: resTextStyle3.copyWith(fontSize: 14, height: 1.5),
              ),
            ),
            SizedBox(
              height: 15,
            ),
            Container(height: 1, color: Colors.black.withOpacity(0.05)),
            Container(
              height: 50,
              child: Row(
                children: [
                  textLeftButton == null
                      ? Container()
                      : Expanded(
                      child: GestureDetector(
                        onTap: () {
                          Navigator.of(context).pop();
                          if (onLeftClick != null) {
                            onLeftClick!();
                          }
                        },
                        child: Container(
                          color: Color(0x01ffffff),
                          child: Center(
                            child: Text(
                              textLeftButton!,
                              style: resTextStyle6.copyWith(
                                  color: Color(0xff666666), fontSize: 16),
                            ),
                          ),
                        ),
                      )),
                  Visibility(
                      visible: textLeftButton != null,
                      child: Container(
                        width: 1,
                        color: Colors.black.withOpacity(0.05),
                      )),
                  Expanded(
                      child: GestureDetector(
                        onTap: () {
                          Navigator.of(context).pop();
                          if (onRightClick != null) onRightClick!();
                        },
                        child: Container(
                          color: Color(0x01ffffff),
                          child: Center(
                            child: Text(
                              textRightButton!,
                              style: resTextStyle6.copyWith(
                                  color: DDialogUtils.ddMainColor,
                                  fontSize: 16),
                            ),
                          ),
                        ),
                      )),
                ],
              ),
            )
          ],
        ),
      ),
    ),);
  }
}
